package core;

import java.util.ArrayList;
import java.util.List;

public abstract class Board {
    protected static final char EMPTY = '·';
    protected static final char BLACK = '●';
    protected static final char WHITE = '○';
    protected static final char LEGAL_MOVE = '+';

    protected char[][] grid;
    protected Player player1;
    protected Player player2;
    protected Player currentPlayer;
    protected boolean gameOver;

    public Board(String player1Name, String player2Name) {
        grid = new char[8][8];
        player1 = new Player(player1Name, BLACK);
        player2 = new Player(player2Name, WHITE);
        currentPlayer = player1;
        gameOver = false;
        initializeBoard();
    }

    protected abstract void initializeBoard();
    public abstract boolean makeMove(int row, int col);
    public abstract void display();

    public Player getCurrentPlayer() {
        return currentPlayer;
    }

    protected void switchPlayer() {
        currentPlayer = (currentPlayer == player1) ? player2 : player1;
    }

    protected boolean isValidPosition(int row, int col) {
        return row >= 0 && row < 8 && col >= 0 && col < 8;
    }

    protected List<int[]> getLegalMoves(Player player) {

        List<int[]> moves = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if (grid[i][j] == EMPTY) {
                    moves.add(new int[]{i, j});
                }
            }
        }
        return moves;
    }
}